﻿using IOP.SgrA.GLSL;
using IOP.SgrA.SilkNet.Vulkan;
using IOP.SgrA.SilkNet.Vulkan.Scripted;
using Silk.NET.Vulkan;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VkSample112
{
    [ShaderVersion("460")]
    [GLSLExtension("GL_ARB_separate_shader_objects : enable")]
    [GLSLExtension("GL_ARB_shading_language_420pack : enable")]
    public partial class CommonVert : GLSLVert
    {
        [PushConstant(64, 0)]
        public ConstantVals myConstantVals {  get; set; }
        [UniformBuffer(0, 0, DescriptorSetTarget.RenderObject)]
        public BufferVals myBufferVals { get; set; }

        [VertInput(0, Format.R32G32B32Sfloat)]
        public vec3 pos {  get; set; }
        [VertInput(1, Format.R32G32Sfloat)]
        public vec2 inTexCoor {  get; set; }

        [ShaderOutput(0)]
        public vec2 outTexCoor { get; set; }

        public override void main()
        {
            float currAngle = myBufferVals.angleSpan * (pos.y - myBufferVals.yStart) / myBufferVals.ySpan;//计算当前顶点扭动(绕中心点选择)的角度
            vec3 tPosition = pos;
            if (pos.y > myBufferVals.yStart)
            {//若不是最下面一层的顶点则计算扭动后的X、Z坐标
                tPosition.x = (cos(currAngle) * pos.x - sin(currAngle) * pos.z);
                tPosition.z = (sin(currAngle) * pos.x + cos(currAngle) * pos.z);
            }
            outTexCoor = inTexCoor;
            gl_Position = myConstantVals.mvp * new vec4(tPosition, 1.0f);
        }
    }
}
